スキップしてメイン コンテンツに移動

Understanding Logistic Regression from Scratch

 Logistic regression is one of the most popular methods at the intersection of statistics and machine learning.


Despite its name including “regression”, it’s actually a classification model that predicts “0 or 1”. 


With its intuitive probabilistic interpretation and simple implementation, it's widely used in a variety of fields, from business to healthcare and web analytics.



1. What is Logistic Regression?



While general linear regression predicts continuous values, logistic regression outputs the probability of an event occurring.


By classifying instances as class 1 if the resulting probability exceeds a threshold, and class 0 if it falls below, it solves binary classification problems.


Estimation is performed by maximising the log-likelihood function to best explain the correct labels.


Mathematically, it involves finding the gradient and iteratively updating, meaning you can complete learning with just a few lines of code using Python’s `scikit-learn` or `statsmodels`.



2. Where is it Used?



Due to its high interpretability and low implementation cost, logistic regression is often the first choice in many industries and applications.


- Medical Diagnosis: Predicting whether a patient has a disease based on test results and medical history.

- Credit Scoring: Determining creditworthiness based on an applicant’s attributes and credit history.

- Customer Churn Prediction: Estimating the risk of cancellation based on purchase history and usage frequency.

- Marketing: Binary classification of email open rates and advertising click-through rates.

- HR & Recruitment: Evaluating candidate suitability and the risk of early departure based on applicant information.

- Anomaly Detection in Manufacturing: Determining the presence of equipment failure based on sensor data.


By looking at the weights and odds ratios, you can intuitively understand how much each explanatory variable influences the result.



3. Benefits of Learning It?



- It’s easy to explain the impact of variables on the result to business stakeholders using odds ratios and the signs of coefficients.

- It’s a good first step to learning evaluation metrics (ROC curve, AUC, Precision-Recall).

- Compared to decision trees or SVMs, it can provide numerical justification for “why” a prediction was made.

- It provides a foundation for developing to multi-class classification (Softmax regression).

- It can serve as foundational knowledge for hierarchical Bayesian models and generalised linear models.

- You can incorporate probabilistic predictions directly into subsequent decision-making, such as credit ratings and patient risk scoring.

- Understanding maximum likelihood estimation, gradient methods, and regularisation can be applied to deep learning.

- Overfitting can be suppressed by combining regularisation and variable selection.

- It can be implemented with just a few lines of code using standard Python/R libraries, and can handle large datasets using mini-batch learning.



Summary



Logistic regression is not only directly applicable to your work but also an essential stepping stone to more advanced algorithms. 


Let’s start by implementing logistic regression with your own hands and experiencing the fun of probabilistic prediction.

If you want to learn logistic regression, we recommend this book (access here).


コメント

このブログの人気の投稿

Verständnis der Trigonometrie von Grund auf: Sinus, Kosinus und Tangens

Die Trigonometrie ist ein besonders tiefgreifendes und breit anwendbares Gebiet innerhalb der Mathematik. Ihre Ursprünge liegen in der antiken griechischen Astronomie und Vermessungskunst, doch ist sie heute ein unverzichtbares Werkzeug in Bereichen von der modernen Technik und Physik bis hin zur Informationstechnologie. Dieser Artikel erklärt zunächst die grundlegenden Konzepte von "Was ist Trigonometrie?", betrachtet anschließend, wie sie in verschiedenen Situationen eingesetzt wird, und erläutert schließlich die Vorteile des Trigonometrielernens. 1. Was ist Trigonometrie? Die Trigonometrie ist eine Menge von Funktionen, die die Beziehung zwischen Winkeln und Seitenlängen in einem rechtwinkligen Dreieck ausdrücken. Die bekanntesten davon sind Sinus (sin), Kosinus (cos) und Tangens (tan). - Definition in einem rechtwinkligen Dreieck In einem rechtwinkligen Dreieck werden trigonometrische Funktionen durch die Verhältnisse der gegenüberliegenden, anliegenden und hypotenusensei...

Understanding the Modified Euler Method (Heun's Method) from Scratch

This article explains the basic concepts, applications, and benefits of learning the Modified Euler Method (Heun's Method). This method, a step forward from the simple Euler method, plays a very important role in the world of numerical analysis. 1. What is the Modified Euler Method (Heun's Method)? The Modified Euler Method, also known as Heun’s Method, is a numerical method for obtaining approximate solutions to initial value problems: dy/dt = f(t, y), y(t_0) = y_0 The traditional Euler method determines the next value, y_{n+1}, using only the slope of the tangent line at time t_n, namely f(t_n, y_n).  However, when the step size is large or the problem exhibits strong non-linearity, this can lead to significant errors. A key feature of Heun’s Method is its ability to achieve higher accuracy (local error of second order) through a two-stage evaluation process, improving upon the Euler method. 2. In What Scenarios is it Applied? Due to its simplicity and improved accuracy, Heun...

Entscheidungsbäume – Ein Leitfaden für Anfänger

In der heutigen datengesteuerten Ära entstehen ständig neue Werkzeuge zur Unterstützung komplexer Entscheidungsfindung. Unter diesen sind „Entscheidungsbäume“ aufgrund ihrer einfachen Verständlichkeit und intuitiven Visualisierung eine beliebte Methode. Hier erklären wir die grundlegenden Konzepte von Entscheidungsbäumen, spezifische Szenarien, in denen sie eingesetzt werden, und die Vorteile, sie zu erlernen. 1. Was sind Entscheidungsbäume? Entscheidungsbäume sind ein Modelltyp, der für Datenklassifizierung und -vorhersage verwendet wird. Sie verwenden eine Baumstruktur, um den Entscheidungsprozess darzustellen. Entscheidungsbäume bestehen aus Knoten (Entscheidungsknoten) und Kanten (Verzweigungen). Jeder Knoten beinhaltet eine bedingte Beurteilung basierend auf einem bestimmten Merkmal, und die Verzweigungen divergieren basierend auf diesem Ergebnis. Letztendlich wird das Klassifikationsergebnis oder der vorhergesagte Wert an den terminalen Teilen, den sogenannten Blattknoten, angeze...